import { defHttp } from '@/utils/http/axios';
import { AxiosPromise } from 'axios';
import { OrderVO, OrderForm, OrderQuery } from '@/api/sale/order/types';

/**
 * 查询订单列表
 * @param query
 * @returns {*}
 */

export const listSaleOrder = (query?: OrderQuery): AxiosPromise<OrderVO[]> => {
  return defHttp.get({
    url: '/sale/order/list',
    params: query,
  });
};

/**
 * 查询订单详细
 * @param id
 */
export const getSaleOrder = (id: string): AxiosPromise<OrderVO> => {
  return defHttp.get({
    url: '/sale/order/' + id,
  });
};

/**
 * 新增订单
 * @param data
 */
export const addSaleOrder = (data: OrderForm) => {
  return defHttp.post({
    url: '/sale/order',
    data: data,
  });
};

/**
 * 修改订单
 * @param data
 */
export const updateSaleOrder = (data: OrderForm) => {
  return defHttp.put({
    url: '/sale/order',
    data: data,
  });
};

/**
 * 删除订单
 * @param ids
 */
export const delSaleOrder = (ids: string | number | Array<string | number>) => {
  return defHttp.delete({
    url: '/sale/order/' + ids,
  });
};

/**
 * 关注、取消关注客户
 * @param data
 */
export const updateCustomer = (data: OrderForm) => {
  return defHttp.put({
    url: '/customer/mast',
    data: data,
  });
};

export function exportSaleOrder() {
  // 一定要加 responseType: 'blob'
  // 一定要加 responseType: 'blob'
  // 一定要加 responseType: 'blob'
  // 否则拿到的是string
  return defHttp.post<Blob>(
    { url: '/sale/order/export', responseType: 'blob' },
    { isTransformResponse: false },
  );
}

/**
 * 新增客户地址
 * @param data
 */
export const addCustomerAddress = (data: any) => {
  return defHttp.post({
    url: '/customer/address',
    data: data,
  });
};

/**
 * 修改客户地址
 * @param data
 */
export const updateCustomerAddress = (data: any) => {
  return defHttp.put({
    url: '/customer/address',
    data: data,
  });
};

/**
 * 获取客户地址
 * @param query
 */
export const getCustomerAddress = (query?: OrderQuery): AxiosPromise<OrderVO[]> => {
  return defHttp.get({
    url: '/customer/address/list',
    params: query,
  });
};

/**
 * 删除客户地址
 * @param addressIds
 */
export const delCustomerAddress = (addressIds: Array<string | number>) => {
  return defHttp.delete({
    url: '/customer/address/' + addressIds,
  });
};

/**
 * 新增客户联系人
 * @param data
 */
export const addCustomerContact = (data: any) => {
  return defHttp.post({
    url: '/customer/contact',
    data: data,
  });
};

/**
 * 修改客户联系人
 * @param data
 */
export const updateCustomerContact = (data: any) => {
  return defHttp.put({
    url: '/customer/contact',
    data: data,
  });
};

/**
 * 查询客户联系人
 * @param customerId
 */
export const getCustomerContact = (query?: OrderQuery): AxiosPromise<OrderVO[]> => {
  return defHttp.get({
    url: '/customer/contact/list',
    params: query,
  });
};

/**
 * 删除客户联系人
 * @param contactIds
 */
export const delCustomerContact = (contactIds: Array<string | number>) => {
  return defHttp.delete({
    url: '/customer/contact/' + contactIds,
  });
};
